﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;

//  Nati Nissim ID: 038589602 
//  Michael Biniashvili ID: 061669966

namespace SimulationHW2
{
    class StudentTable
    {
        public StudentTable()
        {
            InitailTable();
        }

        #region Help function
        private void CreateColumns(string columnName)
        {
            globalColumnsList.Add(columnName);
            columnsMapping.Add(columnName, (typeof(double)));
        }

        private double Trim(double value)
        {
            return Math.Round(value, PropertiesSimulation.Epsilon);
        }
        #endregion

        #region Table student

        private List<string> globalColumnsList = new List<string>();
        private Hashtable columnsMapping = new Hashtable();
        private void InitailTable()
        {
            CreateColumns("-1");
            CreateColumns("1");
            CreateColumns("Zi0");
            CreateColumns("∆Z");
            PropertiesSimulation.StrZ = new string[PropertiesSimulation.Level];

            for (int i = 0; i < globalColumnsList.Count; i++)
            {
               PropertiesSimulation.dataTableZ.Columns.Add(new DataColumn(globalColumnsList[i], (Type)columnsMapping[globalColumnsList[i]]));
            }

            for (int i = 0; i < PropertiesSimulation.Level; i++)
            {
                PropertiesSimulation.dataTableZ.Rows.Add(new object[] { });
            }

            string colLower = globalColumnsList[0];
            string colUpper = globalColumnsList[1];
            string colZio = globalColumnsList[2];
            string colDeltaZ = globalColumnsList[3];
            for (int i = 0; i < PropertiesSimulation.ArrayUpper.Length; i++)
            {
                double zi0 = 0;
                double deltaZ = 0;
                PropertiesSimulation.dataTableZ.Rows[i][colLower] = PropertiesSimulation.ArrayLower[i];
                PropertiesSimulation.dataTableZ.Rows[i][colUpper] = PropertiesSimulation.ArrayUpper[i];
                PropertiesSimulation.dataTableZ.Rows[i][colZio] = zi0 = Trim(((double)PropertiesSimulation.dataTableZ.Rows[i][colUpper] + (double)PropertiesSimulation.dataTableZ.Rows[i][colLower]) / 2);
                PropertiesSimulation.dataTableZ.Rows[i][colDeltaZ] = deltaZ = Trim((double)PropertiesSimulation.dataTableZ.Rows[i][colUpper] - (double)PropertiesSimulation.dataTableZ.Rows[i][colZio]);
                PropertiesSimulation.StrZ[i] = ("X" + (i + 1) + " = " + Trim((1 / deltaZ)) + "(Z" + (i + 1) + ") - " + Trim((zi0 / deltaZ))).ToString();
            }
        }
        #endregion Table student
    }
}
